<template>
	<view class="container">
		<uni-nav-bar class="ch-nav" height="88rpx" backgroundColor="#ffffff" leftWidth="90rpx" rightWidth="90rpx" color="#333" :fixed="true" :padding="false" :border="true" @clickLeft="$goBack(1)">
			<template slot="left">
				<image class="left" src="@/public/images/public/dhl_fhjt.png" mode="aspectFit"></image>
			</template>
			<text class="title">更多视频推荐</text>
			<template slot="right"></template>
		</uni-nav-bar>
		<view class="body flex-c bottom-ios">
			<template v-if="videoList[0]">
				<VideoArticle v-if="type == 'article'" :list="videoList"></VideoArticle>
				<VideoDiscuss v-if="type == 'discuss'" :list="videoList"></VideoDiscuss>
			</template>
			<EmptyContent v-else top="220rpx" text="暂无更新的视频" img="qsy_zwxl" :showRefresh="requestError" @refresh="getSeasonArticles"></EmptyContent>
			<view class="list-end flex-r mb20" v-if="isEnd">
				<text>已经到底啦～</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 'article', //列表类型 [article|discuss]
				videoList: [], //内容列表
				
				requestError: false, //请求错误
				pageNo: 1, //列表页数
				isEnd: false //是否加载完
			};
		},
		components: {//分为两个列表组件，便于后期扩展
			VideoArticle: () => import("./components/ch-video/ch-videoarticle.vue"), //列表
			VideoDiscuss: () => import("./components/ch-video/ch-videodiscuss.vue") //列表
		},
		onLoad() {
			this.type = this.$Route.query.type
			this.getVideoList()
		},
		onReachBottom() {
			if(!this.isEnd){
				this.getVideoList()
			}
		},
		methods: {
			//查询视频列表
			getVideoList(){
				if(this.type === 'article'){
					this.getVideoArticle()
				}else if(this.type === 'discuss'){
					this.getVideoDiscuss()
				}
			},
			//视频料内容列表
			getVideoArticle() {
				this.$http.get({
					url: '/api/user/home/recommended/video/article',
					data: {
						pageNo: this.pageNo,
						pageSize: 15
					}
				}).then(data => {
					console.log(data);
					if(data.success){
						if(data.result && data.result.total){
							if(data.result.current == 1){
								this.videoList = data.result.records
							}else{
								this.videoList.push(...data.result.records)
							}
							this.isEnd = data.result.current >= data.result.pages
							this.pageNo = data.result.current + 1
						}
					}else{
						this.requestError = true
					}
				}).catch((err) => {
					console.log(err);
				})
			},
			//视频贴内容列表
			getVideoDiscuss() {
				this.$http.get({
					url: '/api/user/home/recommended/video/dynamic',
					data: {
						pageNo: this.pageNo,
						pageSize: 15
					}
				}).then(data => {
					console.log(data);
					if(data.success){
						if(data.result && data.result.total){
							if(data.result.current == 1){
								this.videoList = data.result.records
							}else{
								this.videoList.push(...data.result.records)
							}
							this.isEnd = data.result.current >= data.result.pages
							this.pageNo = data.result.current + 1
						}
					}else{
						this.requestError = true
					}
				}).catch((err) => {
					console.log(err);
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		min-height: var(--safe-height);
		background-color: #fff;
		.body{
			padding: 0 20rpx;
			
		}
	}
</style>
